package main

import (
	"fmt"
	"sort"
)

func main() {
	sum := 0
	for i := 0; i <= 10; i++ {
		sum += i
	}
	fmt.Println(sum)

	//for循环的range格式对slice, map, 数组，字符串等进行循环迭代
	strings := []string{"google", "runoob", "baidu"}
	for i, s := range strings {
		fmt.Println(i, s)
	}

	//像C语言
	//for i := 0; i < 10; i++{

	//}

	//c的while
	//for ture{}

	//make用来创建slice， map, chanel类型分配内存和初始化一个对象
	//只能用于这三个类型
	map1 := make(map[int]float32)
	map1[1] = 1.0
	map1[2] = 2.0
	map1[3] = 3.0
	map1[4] = 4.0

	var keys []int
	// 读取 key 和 value
	for key, value := range map1 {
		fmt.Printf("key is: %d - value is: %f\n", key, value)
	}

	for k := range map1 {
		keys = append(keys, k)
	}
	sort.Ints(keys)

	for _, k := range keys {
		fmt.Println("key", k, "value", map1[k])
	}

	// 读取 key
	for key := range map1 {
		fmt.Printf("key is: %d\n", key)
	}

	// 读取 value
	for _, value := range map1 {
		fmt.Printf("value is: %f\n", value)
	}

	//在遍历Go语言中，遍历map是不保证顺序的，每一次遍历的顺序都有可能是不相同的
	//

}
